<template>
  <default-layout>
    <header-back text="党员活动" slot="header"></header-back>
    <div
      v-infinite-scroll="loadMore"
      infinite-scroll-disabled="disabledScroll"
      infinite-scroll-distance="10"
      infinite-scroll-immediate-check="false"
      slot="main"
      class="list scroll-view">
      <div class="item" v-for="(val, key) in list" :key="key" @click="detail(val)">
        <div class="top">
          <div class="title">{{val.title}}</div>
          <div class="status" :class="Number(val.signUpType || 0) === 0 ? 'pending' : Number(val.signUpType || 0) === 2 ? 'success' : 'over'">{{val.signUpTypeName}}</div>
          <!--0: 活动报名  1活动已结束  2已报名  3活动人满-->
        </div>
        <div class="bottom">
          <div class="date">{{val.publishDate}}</div>
          <div class="desc">已报：{{val.personCount}}人，限：{{val.signUpCount}}人</div>
        </div>
      </div>
      <loading-text v-if="loading"></loading-text>
      <finish-text v-if="noMore"></finish-text>
      <empty v-if="empty"></empty>
      <yd-backtop></yd-backtop>
    </div>
    <transition name="router" mode="out-in">
      <router-view class="fixed-router"></router-view>
    </transition>
  </default-layout>
</template>
<script>
  import HeaderBack from '../../../components/header-back/header-back.vue'
  import LoadingText from '../../../components/loading-text/loading-text.vue'
  import FinishText from '../../../components/finish-text/finish-text.vue'
  import DefaultLayout from '../../../layouts/default-layout/default-layout'
  import {infinite} from '../../../common/js/mixin'
  import Empty from '../../../components/empty/empty'

  export default {
    components: {
      Empty,
      DefaultLayout,
      FinishText,
      LoadingText,
      HeaderBack},
    computed: { ...infinite },
    data() {
      return {
        /* 以下五个参数为上拉加载页面必需的参数 */
        loading: true,
        page: 1,
        size: 10,
        total: 0,
        list: []
        /* 以上五个参数为上拉加载页面必需的参数 */
      }
    },
    methods: {
      loadMore() {
        if (this.page === 1) this.list = []
        this.$post('/admin/person/sapi/party/activity/getList', {
          page: this.page,
          rows: this.size
        }, loading => {
          this.loading = loading
        }).then(res => {
          this.list = this.list.concat(res.data.dataList)
          this.total = res.data.pageBean.totalCount
          this.page++
        })
      },
      detail(val) {
        this.$router.push({
          name: 'activity',
          query: {
            id: val.id
          }
        })
      }
    },
    created() {
      this.loadMore()
    }
  }
</script>
<style scoped lang="scss">
  @import "../../../common/style/variable";
  .list{
    .item{
      padding: .2rem;
      display: block;
      background: #fff;
      @include active;
      .title{
        font-size: .32rem;
        font-weight: 300;
        max-width: 70%;
        @include ellipsis;
      }
      .top,.bottom{
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: .1rem 0;
      }
      .date,.desc{
        color: #999;
        font-size: .28rem;
      }
      .status{
        display: inline-block;
        padding: .11rem;
        border-radius: 6px;
        color: #fff;
        &.pending{
          background: #f04a4a;
        }
        &.over{
          background: #bababa;
        }
        &.success{
          background: $primary;
        }
      }
      &:not(:last-child){
        border-bottom: 1px solid #ededed;
      }
    }
  }
</style>
